﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class DIC_STATE
    {
        private string m_Description;
        private decimal m_Price;
        private string m_StateCode;
        private string m_StateName;
        private string m_Unit;

        public DIC_STATE()
        {
            m_StateCode = "";
            m_StateName = "";
            m_Unit = "";
            m_Price = 0M;
            m_Description = "";
        }

        public DIC_STATE(string StateCode, string StateName, string Unit, decimal Price, string Description)
        {
            m_StateCode = StateCode;
            m_StateName = StateName;
            m_Unit = Unit;
            m_Price = Price;
            m_Description = Description;
        }

        [DisplayName("Description"), Category("Column")]
        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        [Category("Column"), DisplayName("Price")]
        public decimal Price
        {
            get { return m_Price; }
            set { m_Price = value; }
        }

        public string ProductName
        {
            get { return "Class DIC_STATE"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        [DisplayName("StateCode"), Category("Primary Key")]
        public string StateCode
        {
            get { return m_StateCode; }
            set { m_StateCode = value; }
        }

        [Category("Column"), DisplayName("StateName")]
        public string StateName
        {
            get { return m_StateName; }
            set { m_StateName = value; }
        }

        [DisplayName("Unit"), Category("Column")]
        public string Unit
        {
            get { return m_Unit; }
            set { m_Unit = value; }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "StateName", "StateCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["StateCode"] = "All";
            row["StateName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "StateName", "StateCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["StateName"]);
            }
        }

        public string Delete()
        {
            string[] myParams = {"@StateCode"};
            object[] myValues = {m_StateCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Delete", myParams, myValues);
        }

        public string Delete(string StateCode)
        {
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string StateCode)
        {
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_STATE_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string StateCode)
        {
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_STATE_Delete", myParams, myValues);
        }

        public bool Exist(string StateCode)
        {
            bool hasRows = false;
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_STATE_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string StateCode)
        {
            string str = "";
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_STATE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StateCode = Convert.ToString(reader["StateCode"]);
                    m_StateName = Convert.ToString(reader["StateName"]);
                    m_Unit = Convert.ToString(reader["Unit"]);
                    m_Price = Convert.ToDecimal(reader["Price"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string StateCode)
        {
            string str = "";
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "DIC_STATE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StateCode = Convert.ToString(reader["StateCode"]);
                    m_StateName = Convert.ToString(reader["StateName"]);
                    m_Unit = Convert.ToString(reader["Unit"]);
                    m_Price = Convert.ToDecimal(reader["Price"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string StateCode)
        {
            string str = "";
            string[] myParams = {"@StateCode"};
            object[] myValues = {StateCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "DIC_STATE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StateCode = Convert.ToString(reader["StateCode"]);
                    m_StateName = Convert.ToString(reader["StateName"]);
                    m_Unit = Convert.ToString(reader["Unit"]);
                    m_Price = Convert.ToDecimal(reader["Price"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("DIC_STATE_GetList");
        }

        public string Insert()
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {m_StateCode, m_StateName, m_Unit, m_Price, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {m_StateCode, m_StateName, m_Unit, m_Price, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_STATE_Insert", myParams, myValues);
        }

        public string Insert(string StateCode, string StateName, string Unit, decimal Price, string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string StateCode, string StateName, string Unit, decimal Price,
            string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_STATE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string StateCode, string StateName, string Unit,
            decimal Price, string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_STATE_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("DIC_STATE", "StateCode", "CD");
        }

        public string Update()
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {m_StateCode, m_StateName, m_Unit, m_Price, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Update", myParams, myValues);
        }

        public string Update(string StateCode, string StateName, string Unit, decimal Price, string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_STATE_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string StateCode, string StateName, string Unit, decimal Price,
            string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_STATE_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string StateCode, string StateName, string Unit,
            decimal Price, string Description)
        {
            string[] myParams = {"@StateCode", "@StateName", "@Unit", "@Price", "@Description"};
            object[] myValues = {StateCode, StateName, Unit, Price, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_STATE_Update", myParams, myValues);
        }
    }
}